﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class ListDifferentWordsInString
{
    static void Main()
    {
        //Exercise 22.
        //Write a program that reads a string from the console and lists all different words in the string along with 
        //information how many times each word is found.

        //Console.Write("Type the text: ");
        //string text = Console.ReadLine();
        string text = "Write a program that reads a string from the console and lists all different words in the string.";

        string[] specialSigns = { " ", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "+", "." };
        string[] words = text.Split();
        for (int i = 0; i < words.Length; i++)
        {
            for (int j = 0; j < specialSigns.Length; j++)
            {
                words[i] = words[i].Replace(specialSigns[j], string.Empty);
            }
        }

        Dictionary<string,int> allWords = new Dictionary<string,int>();
        for (int i = 0; i < words.Length; i++)
        {
            if (allWords.ContainsKey(words[i]))
            {
                allWords[words[i]]++;
            }
            else
            {
                allWords.Add(words[i], 1);
            }
        }
        foreach (var word in allWords)
        {
            Console.WriteLine("Word -> {0} - Counter -> {1}", word.Key, word.Value);
        }

    }
}

